#
# Copyright (C) 2016 Red Hat, Inc. All rights reserved.
#
# This file is part of the device-mapper userspace tools.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU Lesser General Public License v.2.1.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@

SOURCES = dmfilemapd.c

TARGETS = dmfilemapd

.PHONY: install_dmfilemapd install_dmfilemapd_static

INSTALL_DMFILEMAPD_TARGETS = install_dmfilemapd_dynamic

CLEAN_TARGETS = dmfilemapd.static

CFLOW_LIST = $(SOURCES)
CFLOW_LIST_TARGET = $(LIB_NAME).cflow
CFLOW_TARGET = dmfilemapd

include $(top_builddir)/make.tmpl

all: device-mapper
device-mapper: $(TARGETS)

CFLAGS_dmfilemapd.o += $(EXTRA_EXEC_CFLAGS)
LIBS += -ldevmapper

dmfilemapd: $(LIB_SHARED) dmfilemapd.o
	$(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_EXEC_LDFLAGS) $(ELDFLAGS) \
		-o $@ dmfilemapd.o $(DL_LIBS) $(LIBS)

dmfilemapd.static: $(LIB_STATIC) dmfilemapd.o $(interfacebuilddir)/libdevmapper.a
	$(CC) $(CFLAGS) $(LDFLAGS) $(ELDFLAGS) -static -L$(interfacebuilddir) \
		-o $@ dmfilemapd.o $(DL_LIBS) $(LIBS) $(STATIC_LIBS)

ifneq ("$(CFLOW_CMD)", "")
CFLOW_SOURCES = $(addprefix $(srcdir)/, $(SOURCES))
-include $(top_builddir)/libdm/libdevmapper.cflow
-include $(top_builddir)/lib/liblvm-internal.cflow
-include $(top_builddir)/lib/liblvm2cmd.cflow
-include $(top_builddir)/daemons/dmfilemapd/$(LIB_NAME).cflow
endif

install_dmfilemapd_dynamic: dmfilemapd
	$(INSTALL_PROGRAM) -D $< $(sbindir)/$(<F)

install_dmfilemapd_static: dmfilemapd.static
	$(INSTALL_PROGRAM) -D $< $(staticdir)/$(<F)

install_dmfilemapd: $(INSTALL_DMFILEMAPD_TARGETS)

install: install_dmfilemapd

install_device-mapper: install_dmfilemapd
